#include "msgboxdlg.h"

MsgBoxDlg::MsgBoxDlg(QDialog *parent) : QDialog(parent)
{
    setWindowTitle(tr("各种消息框"));
    mainLayout = new QGridLayout(this);

    label = new QLabel(tr("plz select a Msg"));
    mainLayout->addWidget(label, 0, 0, 1, 2);

    questionBtn = new QPushButton(tr("qusetion Msg"));
    connect(questionBtn, &QPushButton::clicked, this, &MsgBoxDlg::showQuestion);
    mainLayout->addWidget(questionBtn,1, 0);

    informationBtn = new QPushButton(tr("information Msg"));
    connect(informationBtn, &QPushButton::clicked, this, &MsgBoxDlg::showInfomation);
    mainLayout->addWidget(informationBtn, 1, 1);

    warningBtn = new QPushButton(tr("warning Msg"));
    connect(warningBtn, &QPushButton::clicked, this, &MsgBoxDlg::showWarning);
    mainLayout->addWidget(warningBtn, 2, 0);

    criticalBtn = new QPushButton(tr("critical Msg"));
    connect(criticalBtn, &QPushButton::clicked, this, &MsgBoxDlg::showCritical);
    mainLayout->addWidget(criticalBtn, 2, 1);

    aboutBtn = new QPushButton(tr("about Msg"));
    connect(aboutBtn, &QPushButton::clicked, this, &MsgBoxDlg::showAbout);
    mainLayout->addWidget(aboutBtn, 3, 0);

    aboutQtBtn = new QPushButton(tr("aboutQt Msg"));
    connect(aboutQtBtn, &QPushButton::clicked, this, &MsgBoxDlg::showAboutQt);
    mainLayout->addWidget(aboutQtBtn, 3, 1);
}



void MsgBoxDlg::showQuestion()
{
    // 使用QMessageBox::question()函数完成
    label->setText(tr("Question Msg Box"));

    switch (QMessageBox::question(this, tr("question Msg"), tr("question has over, did ok?"), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok))
    {
    case QMessageBox::Ok:
        label->setText(tr("OK"));
        break;
    case QMessageBox::Cancel:
        label->setText(tr("CANCEL"));
        break;
    default:
        break;
    }

    return;
}

void MsgBoxDlg::showInfomation()
{
    // 使用QMessageBox::information()函数完成
    label->setText(tr("Information Msg Box"));

    QMessageBox::information(this, tr("information Msg"), tr("this is a information"));

    return;
}

void MsgBoxDlg::showWarning()
{
    // 使用QMessageBox::warning()函数完成
    label->setText(tr("Warning Msg Box"));

    switch ( QMessageBox::warning(this, tr("warning Msg"), tr("do you want to save?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save))
    {
    case QMessageBox::Save:
        label->setText(tr("SAVE"));
        break;
    case QMessageBox::Discard:
        label->setText(tr("discard"));
        break;
    case QMessageBox::Cancel:
        label->setText(tr("CANCEL"));
        break;
    default:
        break;
    }

    return;
}

void MsgBoxDlg::showCritical()
{
    // 使用QMessageBox::cirtical()函数完成，有错误时使用
    label->setText(tr("Critical Msg Box"));

    QMessageBox::critical(this, tr("critical Msg"), tr("this is a critical box"));

    return;
}

void MsgBoxDlg::showAbout()
{
    // 使用QMessageBox::about()函数完成
    label->setText(tr("About Msg Box"));

    QMessageBox::about(this, tr("about Msg"), tr("this is a about box"));

    return;
}

void MsgBoxDlg::showAboutQt()
{
    // 使用QMessageBox::aboutQt()函数完成
    label->setText(tr("AboutQt Msg Box"));

    QMessageBox::aboutQt(this, tr("aboutQt Msg"));

    return;
}
